//
//  CameraViewController.m
//  WuliHanhan
//
//  Created by chen tang on 16/2/29.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "CameraViewController.h"
#import "Header.h"



@interface CameraViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
    UIImageView *_showImageView;
}

@end

@implementation CameraViewController


- (void)loadView
{
    [super loadView];
    
    [self.navigationController setNavigationBarHidden:YES];
    
    self.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.showsCameraControls = NO;
    [self setDelegate:self];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(90, heightView-100.0, 90, 90)];
    [button setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:button];
    
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];

    _showImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_showImageView];
    [_showImageView setHidden:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    //保存到相册
    
    
    
    //拍照结束生成预览界面
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), NULL);
//    [self.view showTakePhotoImage:image];
}



- (void)buttonClick
{
    [self takePicture];
}




//保存图片进行刷新
- (void)savedPhotoImage:(UIImage*)image didFinishSavingWithError:(NSError *)error contextInfo: (void *)contextInfo
{
    [[NSNotificationCenter defaultCenter] postNotificationName:imageSaveSuccess object:nil];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
